package org.ucas.faker.web.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.ucas.faker.web.entity.SpecialKeyword;

import java.util.List;

import javax.transaction.Transactional;

@Repository
public interface SpecialKeywordDao extends JpaRepository<SpecialKeyword, Long> {
  //@Query("")
  public List<SpecialKeyword> findByTreeId(long treeId);
  
  public void deleteById(Long id);
  
  @Transactional
  @Modifying(clearAutomatically=true)
  @Query(value="update spkeyword sp set sp.keyword_value = ?1 where sp.id = ?2", nativeQuery= true) 
  public int setKeywordValueById(String keyword_value, Long id);
  
  @Transactional
  public void deleteByTreeId(Long treeId);

//  @Query("SELECT meta.id FROM PatentMeta meta WHERE meta.flowId = ?1 AND meta.selected = 1 and meta.extracted = false")
//  public List<Long> toGenIds(long flowId);
//
//  @Modifying
//  @Query("UPDATE PatentMeta meta SET meta.extracted = true WHERE meta.id = :id")
//  public void setGenerated(@Param(value = "id") long id);
//
//  @Modifying
//  @Query("UPDATE PatentMeta meta SET meta.selected = :target WHERE meta.id = :id")
//  public void updateSelected(@Param(value = "id") long id, @Param(value = "target") int target);
//
//  @Modifying
//  @Query("UPDATE PatentMeta meta SET meta.selected = :target WHERE meta.id in :ids")
//  public void updateSelected(@Param(value = "ids") List<Long> ids, @Param(value = "target") int target);
//
//  @Query("SELECT count(*) FROM PatentMeta meta WHERE meta.flowId = ?1 AND meta.selected = 1")
//  public Long countSelected(long flowID);

}
